﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PsychveyApp1.classes;
using System.Collections;

namespace PsychveyApp1
{
    public partial class AnonymousAnswerSurveyHome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Home_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx");
        }

        protected void btnEnterSurvey_Click(object sender, EventArgs e)
        {
           

            Survey s1 = DBManager.GetSurveyById(tbxEnteredSurveyID.Text);
            if (s1.surveyID != null) // if survey exist in db
            {
                string surveyid = tbxEnteredSurveyID.Text.Trim();
                //Session["surveyid"] = surveyid;
                string querystring = "surveyid=" + surveyid;
                Session["surveyid"] = querystring;
                Survey survey2 = new Survey();
                survey2.surveyID = surveyid;

                Session["CurrentPageNumber"] = 1;
               

                //create new anonymous useraccount and store in db
                UserAccount user = new UserAccount();
                user.userID = "PSUser_Anonymous_" + tbxEnteredSurveyID.Text + "_" + DateTime.Now.Second + "/" + DateTime.Now.Minute + "/" + DateTime.Now.Hour + 
                    "/" + DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                user.username = "Anonymous";
                user.password = "";
                user.retypePassword = "";
                user.email = "";
                user.expirationDateForPremium = "";
                user.accountTypeSelected = "Anonymous";
                user.paymentStatus = "";
                user.checkAdministratorStatus = "";
                user.paymentID = "";
                user.userFullName = "";
                user.receiptID = "";
                user.planID = "07";

                Session["currentUser"] = user;

                DBManager.InsertUser(user);
                //Response.Redirect("DisplayedInformationSheet.aspx");
                Server.Transfer("AnonymousAnswerSurvey.aspx?" + querystring);
                
            }
            //Server.TransferRequest("AnswerSurvey.aspx?" + querystring);
            else
            {
                lblSurveyIDNotFound.Text = "SurveyID not found!";
            }
        }

        protected void tbxEnteredSurveyID_TextChanged(object sender, EventArgs e)
        {

        }
    }
}